package ihm.overlays;

import ihm.dialog.windows.EditProfileDialogWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Label;

import tools.ImageConverter;
import tools.LocalUserIHMTest;
import tools.Test;

public class ProfileOverlay implements MainOverlay
{

	private Label lastNameTextArea;
	private Label firstNameTextArea;
	private Label birthDateTextArea;
	private Label addressTextArea;
	private Label eMailTextArea;
	private Label phoneNumberTextArea;
	private Label hobbiesTextArea;
	private Image picture;
	private Label profilePicture;
	private Label portTextArea;
	// TODO
	// private Label broadcastTextArea;
	private Button editProfileButton;

	private Composite composite;

	private ProfileOverlay()
	{
	}
	
	public ProfileOverlay( Shell shell )
	{
		composite = new Composite( shell, SWT.NONE );
		composite.setLayout( new GridLayout( 1, true ) );
		composite.setLayoutData( new GridData( SWT.CENTER, SWT.UP, false, false ) );
		profilePicture = new Label( composite, SWT.None );
		lastNameTextArea = new Label( composite, SWT.NONE );
		firstNameTextArea = new Label( composite, SWT.NONE );
		birthDateTextArea = new Label( composite, SWT.NONE );
		addressTextArea = new Label( composite, SWT.NONE );
		eMailTextArea = new Label( composite, SWT.NONE );
		phoneNumberTextArea = new Label( composite, SWT.NONE );
		hobbiesTextArea = new Label( composite, SWT.NONE );
		portTextArea = new Label( composite, SWT.NONE );
		editProfileButton = new Button( composite, SWT.PUSH );
		editProfileButton.setText( "Modifier Profil" );
		editProfileButton.addSelectionListener( new SelectionAdapter() {
			public void widgetSelected( SelectionEvent e ) {
				System.out.println( "OK" );
				new EditProfileDialogWindow();
			}
		});
	}

	public void updateProfile( LocalUserIHMTest localUser )
	{
		try {
			picture = ImageConverter.makeSWTImage( Display.getCurrent(), Test.getInstance().imageIcon.getImage() );
			profilePicture.setImage( picture );
		} catch (Exception e) {
			e.printStackTrace();
		}
		lastNameTextArea.setText( localUser.lastName );
		firstNameTextArea.setText( localUser.firstName );
		birthDateTextArea.setText( localUser.birthDate );
		addressTextArea.setText( localUser.address );
		eMailTextArea.setText( localUser.email );
		phoneNumberTextArea.setText( localUser.telNumber );
		hobbiesTextArea.setText( localUser.hobbies );
		portTextArea.setText( "port " + localUser.port );
		
	}

}
